// 设置cookie
export const setCookie = (name, value, day) => {
  if (day) {
    let nowDate = new Date();
    // 得到过期时间
    nowDate.setDate(nowDate.getDate() + day);
    document.cookie = `${name}=${value};expires=${nowDate}`;
  } else {
    document.cookie = `${name}=${value}`;
  }
}

// 获取cookie
export const getCookie = name => {
  try {
    let arr = document.cookie.split(';');
    let tmpVal = '';
    arr.forEach(item => {
      let key = item.split('=')[0].trim();
      if (key === name) {
        let val = item.split('=')[1];
        tmpVal = val;
      }
    })
    return tmpVal;
  } catch (e) {
    return '';
  }
}